$(function(){
	parent.IndexPage.toggleLocker('close'); // 沉浸式体验
});
var ExpensePage = {
	'queryByCondition': function() {
		datatable.refresh();
	},
	'afterReady' :function() {
		findStatisticInfoAjax.send();
	},
	'openAddDialog': function() {
		// 打开对话框
		MsgBox.open("openAddDialog", "新增消费记录", ctx + "/expense/add/" + $.uuid() + "/index", "999px");
	},
	'view': function(item, e, rowNumber) {
		MsgBox.open("openViewDialog", "消费记录详情", ctx + "/expense/detail/" + item.id + "/index", "999px");
	},
	'update': function(item, e, rowNumber) {
		MsgBox.open("openUpdateDialog", "修改消费记录", ctx + "/expense/update/" + item.id + "/index", "999px");
	},
	'delete': function(item, e, rowNumber) {
		MsgBox.confirm("确认删除消费记录【" + item.productName + "】吗？", null, function() {
            deleteByIdAjax.tempUrl(function(url) {
                return url + item.id;
            }).send();
        });
	},
	'onDeleteSucc': function(data, status, xhr) {
		$.messager.info(data.message);
		datatable.refresh(false);
	},
	// 选中统计
	'onChecksChanged': function(checkItems,checkAll,currentItem) {
		var amounts = $.toPropertyValueArray(checkItems, 'consumeAmount');
		var gs = new GenericSet(amounts);
		var sum = gs.sumWithFloat();
		$("input[name='countConsumeAmountSelect']").val(sum.toFixed(2));
	},
	'findStatisticInfoSucc': function(data, status, xhr) {
		$("#expenseFrm").find(".t-statistics-bar").autofill(data.info);
	},
	'isCountTime': function(item, rowNumber) {
		var distance = DateUtil.getDaysDistance(item.consumeTime);
		var str = '是，距今' + distance +  '天';
		return str;
	},
	'onDoubleClick': function(item, index) {
		ExpensePage.view(item);
	},
	// 查看月分期详情
	'viewMthInstalmentDetail': function() {
		var searchConsumeTime = $("#expenseFrm").find("input[name='searchConsumeTime']").val();
		if (StringUtil.isBlank(searchConsumeTime)) {
			searchConsumeTime = '-';
		}
		// 自定义标题
		var title = null;
		if (searchConsumeTime == '-') {
			MsgBox.info("请选择月份【消费时间】！");
			return ;
		} else {
			title = '【' + searchConsumeTime + '】月及下月分期详情';
		}
		MsgBox.open("viewMthInstalmentDetail", title, ctx + "/expense/mthInstalmentDetail/" + searchConsumeTime + "/index", "999px");
	}
};